// 1. 加载 express 模块
var express = require('express');
// 2. 创建一个 app 对象（类似于创建一个 server 对象）
var app = express();
// 3. 启动服务
app.listen(8081, function() {
    console.log('http://localhost:8081');
});

app.all('*', (req, res, next) => {
    console.log("-----all------");
    res.setHeader("Access-Control-Allow-Origin", "*");
    next();
})

app.post('/test/post', (req, res) => {
    console.log("-----post------");
    res.send("this is post request");

})
app.get('/menuList', (req, res) => {
    console.log(req.params);
    var menuList = [
        { id: '1', name: '单人特色套餐' },
        { id: '2', name: '特色粥品' },
        { id: '3', name: '精选热菜' },
        { id: '4', name: '爽口凉菜' },
        { id: '5', name: '半成品' },
        { id: '6', name: '饭类' },
        { id: '7', name: '面类' }
    ]
    res.send(menuList)

})

app.get('/goodList', function(req, res) {
    console.log(req.query);
    var goodsList = [
        { id: 1, img: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png', name: '大米饭套餐', price: '19', menuId: '1' },
        { id: 2, img: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png', name: '小米饭套餐', price: '20', menuId: '1' },
        { id: 3, img: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png', name: '小米粥', price: '10', menuId: '2' },
        { id: 4, img: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png', name: '玉米粥', price: '20', menuId: '2' },
        { id: 5, img: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png', name: '八宝粥', price: '20', menuId: '2' },
        { id: 6, img: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png', name: '莲子粥', price: '20', menuId: '2' },
        { id: 7, img: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png', name: '鱼香肉丝', price: '10', menuId: '3' },
        { id: 8, img: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png', name: '肉末茄子', price: '20', menuId: '3' },
        { id: 9, img: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png', name: '无情哈拉少', price: '20', menuId: '3' },
        { id: 10, img: 'https://s1.ax1x.com/2022/07/25/jx9ehV.png', name: '宫保鸡丁', price: '20', menuId: '3' },
    ]
    var nowArray = goodsList.filter((e) => e.name == req.query.name);
    console.log(nowArray);
    res.send(nowArray);
});